package org.jeecg.modules.third.jg.jss.report.cfcshipperinfo.service;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.third.jg.jss.report.cfcshipperinfo.entity.CfcShipperinfo;
import org.jeecg.modules.third.jg.jss.report.cfcshipperinfo.mapper.CfcShipperinfoMapper;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.hyconfig.entity.HyConfig;
import org.jeecg.modules.wlhy.utils.HyConfigUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 托运人信息
 * @Description: CFC_SHIPPERINFO
 * @Author: jeecg-boot
 * @Date:   2021-11-25
 * @Version: V1.0
 */
@Service
public class CfcShipperinfoService{


    @Resource
    private CfcShipperinfoMapper cfcShipperinfoMapper;

    public String getEnterpriseCode() {
        return enterpriseCode;
    }

    public void setEnterpriseCode(String enterpriseCode) {
        this.enterpriseCode = enterpriseCode;
    }

    private String enterpriseCode;


    public CfcShipperinfo getShipperinfo(String shipperid) {
        return cfcShipperinfoMapper.selectShipperinfo( shipperid );
    }


    public CfcShipperinfo selectShipperinfoByShippername(String shippername) {
        return cfcShipperinfoMapper.selectShipperinfoByShippername( shippername );
    }


    public int addShipperinfo(HyCustomer customer) {

        CfcShipperinfo cfcShipperinfo = cfcShipperinfoMapper.selectShipperinfo(customer.getId());
        if (cfcShipperinfo != null) {
            return 0;
        }

        cfcShipperinfo =  customerTOShipperinfo(customer);
        return  cfcShipperinfoMapper.inserShipperinfo(cfcShipperinfo);
    }

    public CfcShipperinfo customerTOShipperinfo(HyCustomer customer){
        if (customer == null) {
            return null;
        }
        CfcShipperinfo cfcShipperinfo = new CfcShipperinfo();
        cfcShipperinfo.setPlatformcode(this.getEnterpriseCode());

        cfcShipperinfo.setShipperid(customer.getId());
        cfcShipperinfo.setShippertype(customer.getCustomerType());

        cfcShipperinfo.setShippername(customer.getCustomerName());
        cfcShipperinfo.setContactname(StrUtil.isEmpty(customer.getContactName()) ? customer.getLegalName() : customer.getContactName());
        cfcShipperinfo.setContactmobiletelephonenumber(customer.getLoginPhone());
        cfcShipperinfo.setUnifiedsocialcreditldentifier(
                StringUtils.equals("1" ,customer.getCustomerType()) ? customer.getIdcard() : customer.getCreditCode()
        );
        cfcShipperinfo.setUnifiedsocialdatetime(customer.getClrq());
        cfcShipperinfo.setRegistrationdatetime(customer.getCreateTime());
        cfcShipperinfo.setContactidcard(customer.getIdcard());

        return cfcShipperinfo;
    }
}
